/**
 * @author Tin Pham / 7inpham@gmail.com
 */
 
Tinz.IslandWorld = function(assets) {
	THREE.Scene.call(this);
	// LIGHTS
	var ambient = new THREE.AmbientLight(0xeeeeee);
	this.add(ambient);
	//this.scene.fog = new THREE.FogExp2(0x9999ff, 0.00025);
	this.fog = new THREE.Fog(0x34583e, 0, 10000);
	this.heightMap = THREEx.Terrain.allocateHeightMap(128, 128);
	THREEx.Terrain.simplexHeightMap(this.heightMap);

	var groundGeometry = THREEx.Terrain.heightMapToPlaneGeometry(this.heightMap);
	THREEx.Terrain.heightMapToVertexColor(this.heightMap, groundGeometry);
	
	var material = new THREE.MeshPhongMaterial({
		map: assets[2],
		ambient: 0xaaaaaa,
		specular: 0xffffff,
		shininess: 0,
		shading: THREE.SmoothShading
	});
	
	var material = new THREE.MeshPhongMaterial({
		shading: THREE.SmoothShading, //shading: THREE.FlatShading,
		vertexColors: THREE.VertexColors
	});
	
	this.ground = new THREE.Mesh(groundGeometry, material);
	this.ground.rotateX(-Math.PI / 2);
	this.ground.scale.x = 20 * 200;
	this.ground.scale.y = 20 * 150;
	this.ground.scale.z = 1 * 200;
	this.add(this.ground);

	// SKYBOX
	//var skyBoxGeometry = new THREE.CubeGeometry( 20000, 20000, 10000 );
	//var skyBoxMaterial = new THREE.MeshBasicMaterial( { color: 0x9999ff, side: THREE.BackSide } );
	//var skyBox = new THREE.Mesh( skyBoxGeometry, skyBoxMaterial );
	//this.mesh.add(skyBox);

	// SKYBOX
	/*
	var skyBoxGeometry = new THREE.CubeGeometry(10000, 10000, 10000);
	var skyBoxMaterial = new THREE.MeshBasicMaterial({
		color: 0x9999ff,
		side: THREE.BackSide
	});
	var skyBox = new THREE.Mesh(skyBoxGeometry, skyBoxMaterial);
	this.mesh.add(skyBox);
	*/
	//this.__initSky();
};

Tinz.IslandWorld.prototype = Object.create(THREE.Scene.prototype);


Tinz.IslandWorld.prototype.__initSky = function() {
	var mesh = THREEx.createSkymap('skybox');
	mesh.position.y = 300;
	mesh.scale.x = 8;
	mesh.scale.y = 2;
	mesh.scale.z = 6;
	this.mesh.add(mesh);
};
